package com.cljz.makepassenger.present.activity;



import com.cljz.makepassenger.base.BaseP;
import com.cljz.makepassenger.model.net.api.Api;
import com.cljz.makepassenger.model.net.bean.GetBillListBean;
import com.cljz.makepassenger.ui.activity.MyWalletActivity;
import com.clzj.makepassenger.bean.UserInfo;

import java.util.HashMap;

import cn.droidlover.xdroidmvp.net.ApiSubcriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;
import cn.droidlover.xdroidmvp.net.diy.Base64Utils;
import okhttp3.RequestBody;

public class MyWalletP extends BaseP<MyWalletActivity> {

    public boolean checkPwd() {
        UserInfo userInfo = getLocalUserInfo(getToken());
        return  !"0".equals(userInfo.getPayment_password());
    }

    public void getBillList(int page) {
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("token", getToken());
        paramsMap.put("page", String.valueOf(page));
        String body = Base64Utils.enCode(gson.toJson(paramsMap));
        RequestBody requestBody = RequestBody.create(okhttp3.MediaType.parse("text/plain;charset=UTF-8"), body);
        Api.getResponseInfoAPI().getBillListData(requestBody)
                .compose(XApi.<GetBillListBean>getApiTransformer())
                .compose(XApi.<GetBillListBean>getScheduler())
                .compose(getV().<GetBillListBean>bindToLifecycle())
                .subscribe(new ApiSubcriber<GetBillListBean>() {
                    @Override
                    protected void onFail(NetError error) {
                        getV().getBillListFail(error.toString());
                    }

                    @Override
                    public void onNext(GetBillListBean getBillListBean) {
                        if ("0".equals(getBillListBean.getError_code())) {
                            getV().getBillListSucceed(getBillListBean.getData());
                        } else if ("1000".equals(getBillListBean.getError_code())) {
                            getV().loginOvertime(1);
                        } else {
                            getV().getBillListFail(getBillListBean.getMsg());
                        }
                    }
                });
    }
}
